# Maintainer: melak47 <melak47@gmail.com>
# Contributor: Andrew Sun <adsun701@gmail.com>
# Contributor: Beat Bolli <dev@drbeat.li>

_realname=fmt
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=7.0.3
pkgrel=1
pkgdesc="A small, safe and fast formatting library for C++ (mingw-w64)"
arch=('any')
url="https://fmt.dev"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/fmtlib/${_realname}/archive/${pkgver}.tar.gz")
sha256sums=('b4b51bc16288e2281cddc59c28f0b4f84fed58d016fb038273a09f05f8473297')

build() {
  # Shared Build
  [[ -d "build-${MINGW_CHOST}-shared" ]] && rm -rf "build-${MINGW_CHOST}-shared"
  mkdir -p ${srcdir}/build-${MINGW_CHOST}-shared
  cd ${srcdir}/build-${MINGW_CHOST}-shared
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=ON \
    -DFMT_TEST=OFF \
    ../${_realname}-${pkgver}

  make -j1 # parallel jobs break build

  # Static Build
  [[ -d "build-${MINGW_CHOST}-static" ]] && rm -rf "build-${MINGW_CHOST}-static"
  mkdir -p ${srcdir}/build-${MINGW_CHOST}-static
  cd ${srcdir}/build-${MINGW_CHOST}-static
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=OFF \
    -DFMT_TEST=OFF \
    ../${_realname}-${pkgver}

  make -j1 # parallel jobs break build
}

package() {
  # Shared Install
  cd "${srcdir}/build-${MINGW_CHOST}-shared"
  make DESTDIR=${pkgdir} install

  # Static Install
  cd "${srcdir}/build-${MINGW_CHOST}-static"
  make DESTDIR=${pkgdir} install

  # Copy the source files for including
  install -m644 ${srcdir}/${_realname}-${pkgver}/src/*.cc ${pkgdir}${MINGW_PREFIX}/include/${_realname}

  # License
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE.rst ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.rst
}
